﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;

using ProjectBase.Core;

namespace ProjectBase.Mvc
{
    public class TextOrTextArea : TextPropertyControl<object, TextOrTextArea>
    {
        #region members
        int _colCount = 100;
        int _rowCount = 100;
        #endregion members

        #region constructor
        public TextOrTextArea() { }

        public TextOrTextArea(bool? asReadonly = null, int? colCount = null, int? rowCount = null)
            : base(asReadonly)
        {
            if (colCount.HasValue)
            {
                _colCount = colCount.Value;
            }
            if (rowCount.HasValue)
            {
                _rowCount = rowCount.Value;
            }
        }
        #endregion constructor

        #region Render
        protected override void ReadControls()
        {
            Controls.Add
                (
                    new Pre()
                        .SetCssClassName(GetAttribute(Attr.Class))
                        .AddCssClassName("scrollAuto")
                        .SetAttribute(Attr.ID, InputName)
                        .AddControls
                        (
                            new Literal(Text)
                        )
                );
        }

        protected override void WriteControls()
        {
            Controls.Add
                (
                    new Textarea()
                        .SetCssClassName(GetAttribute(Attr.Class))
                        .SetAttribute(Attr.ID, InputName)
                        .SetName(InputName)
                        .SetRowCount(RowCount.ToString(CultureInfo.InvariantCulture))
                        .SetColCount(ColCount.ToString(CultureInfo.InvariantCulture))
                        .AddControls
                        (
                            new Literal(Text)
                        )
                );
        }
        #endregion Render

        #region public Set()
        public virtual TextOrTextArea SetColCount(int colCount)
        {
            ColCount = colCount;
            return this;
        }

        public virtual TextOrTextArea SetRowCount(int rowCount)
        {
            RowCount = rowCount;
            return this;
        }
        #endregion public Set()

        #region properties
        public virtual int ColCount
        {
            get { return _colCount; }
            set { _colCount = value; }
        }

        public virtual int RowCount
        {
            get { return _rowCount; }
            set { _rowCount = value; }
        }
        #endregion properties
    }
}